//
//  TodayRightItemViewController.m
//  SYiDaiy
//
//  Created by dllo on 16/9/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TodayRightItemViewController.h"
#import "TAMacro.h"
#import "TodayRightCollectionViewCell.h"
#import "TodayViewController.h"

@interface TodayRightItemViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,strong) UICollectionView *rightCollection;
@property (nonatomic,strong) UICollectionViewFlowLayout *flow;
@end

@implementation TodayRightItemViewController
#pragma mark -------todayright试图加载
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    _flow = [UICollectionViewFlowLayout new];
    
    
    CGSize size =  CGSizeMake((SCREEN_WIDTH - 30) / 2, 150);
    [_flow setItemSize:size];
    [_flow setMinimumInteritemSpacing:10];
    [_flow setMinimumLineSpacing:10];
    UIEdgeInsets inset = UIEdgeInsetsMake(10, 10, 10, 10);
    [_flow setSectionInset:inset];
    
    
    
    
    _rightCollection = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:_flow];
    [_rightCollection setDataSource:self];
    [_rightCollection setDelegate:self];
    [self.view addSubview:_rightCollection];
    
    
        [_rightCollection registerClass:[TodayRightCollectionViewCell class] forCellWithReuseIdentifier:@"rightCell"];
    
    _rightCollection.backgroundColor = [UIColor colorWithWhite:0.854 alpha:1.000];

    
    
    
    
}

#pragma mark -----todayright集合视图返回cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TodayRightCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"rightCell" forIndexPath:indexPath];
   
    
    NSInteger row = indexPath.row;
    Esarray *esarray = [_todayArray objectAtIndex:row];
    
    NSString *str = [esarray cover_thumb_hd];
    
  
    
    [cell.mainImageView sd_setImageWithURL:[NSURL URLWithString:str]];
    cell.titleLabel.text = esarray.title;
    cell.titleLabel.textColor = [UIColor whiteColor];
    
    cell.pubdateLabel.text = esarray.pubdate;
    cell.pubdateLabel.textColor = [UIColor whiteColor];
    return cell;
    
    
}

#pragma mark -----todayright集合视图item的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _todayArray.count;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    TodayViewController *todayVC = [TodayViewController new];

    todayVC.rowValue = indexPath.row;
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
